import {InvokeData} from './invoke-data';
import {RequestParam} from './request-param';
import {RequestBodyDto} from './request-body-dto';
import {EnvItem} from './env-item';

export class InvokeDataRest extends InvokeData {

    /**
     * RESTful调用方法
     */
    method: string;

    /**
     * RESTful调用URL
     */
    url: string;

    /**
     * 环境
     */
    env: EnvItem;

    /**
     * 路径参数
     */
    pathParams: RequestParam[];

    /**
     * Get参数
     */
    params: RequestParam[];

    /**
     * 请求头
     */
    headers: RequestParam[];

    /**
     * Post Body内容
     */
    requestBody: RequestBodyDto;


    public setContentType(contentType: string): void {
        if (!this.headers) {
            this.headers = RequestParam.getDefaultHeaders();
        }
        this.headers.forEach(header => {
            if (header.key === 'Content-Type') {
                header.value = contentType;
            }
        });
    }

    public getContentType(): string {
        let contentType = 'application/json';
        if (this.headers) {
            this.headers.forEach(header => {
                if (header.key === 'Content-Type') {
                    contentType = header.value;
                }
            });
        }
        return contentType;

    }
}
